package cn.tutu.blockchain.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

import cn.tutu.blockchain.bank.entity.Bank;
import cn.tutu.blockchain.bank.service.BankService;
import cn.tutu.blockchain.common.MsgObj;
import cn.tutu.blockchain.common.Page;

@RequestMapping("/bank")
@RestController
@Validated
public class BankController {

	private static Logger LOGGER = LoggerFactory.getLogger(SysuserController.class);
	@Autowired
	private BankService bankService;

	@RequestMapping("/getGridByUser")
	public MsgObj getGridByUser(String userId, Page page) {
		PageInfo<Bank> byModel = bankService.getByUserId(userId, page);
		return MsgObj.buildSuccessObj(byModel.getList());
	}

	@RequestMapping(value = "/create", method = RequestMethod.POST)
	public MsgObj create(@Valid Bank bank) {
		LOGGER.info("创建银行卡信息：[{}]", bank.toString());

		bankService.create(bank);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping(value = "/modify")
	public MsgObj modify(Bank bank) {
		LOGGER.info("修改银行卡信息：[{}]", bank.toString());
		bankService.modify(bank);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/remove")
	public MsgObj remove(String id) {
		LOGGER.info("删除银行卡信息：id[{}]", id);
		bankService.remove(id);
		return MsgObj.buildSuccessMsg();
	}

}
